<template>

		<el-card style="height: 100%;">
   <el-scrollbar
         wrapClass="scrollbar-wrap"
         :style="{height: scrollHeight}"
         ref="scrollbarContainer">
				 <el-select  v-model="tikuId" placeholder="请选择" @change="getTiMuList(tikuId)" style="margin: 25px 0;">
				    <el-option
				      v-for="item in tikuList"
				      :key="item.id"
				      :label="item.name"
				      :value="item.id">
				    </el-option>
				  </el-select>
				  <el-button v-if="tikuId" @click="xzst()">新增题目</el-button>
					 <el-table
					      :data="tableData"
					      style="width: 100%">
					      <el-table-column
					        prop="type"
					        label="题目类型"
					        >
					      </el-table-column>
					      <el-table-column
					        prop="timu"
					        label="题目内容"
					       >
					      </el-table-column>
					     <el-table-column
					       prop="zhishi.name"
					       label="知识点"
					      >
					     </el-table-column>
						 <el-table-column
						   fixed="right"
						   label="操作"
						   >
						   <template slot-scope="scope">
						     <el-button @click="deletea(scope.row)" type="text" size="small">删除</el-button>
						   </template>
						 </el-table-column>
					    </el-table>
              </el-scrollbar>
		</el-card>
</template>

<script>
	export default{
		data() {
			return {
        scrollHeight:'0px',
				tikuList:[],
				tikuId:'',
				tableData:[]
			}
		},
    mounted(){
          this.scrollHeight = window.innerHeight*0.84 + 'px';
      },
		methods:{
			deletea(row) {
					console.log(row);
					  this.$ajax.post("/tiku/delete",{"id":row.id}).then(res=>{
						  if(res.data.success){
							  this.getTikuList()
						  }
				   })
			},
			getTikuList(){
				this.$ajax.post("/tiku/list",{}).then(res=>{
					var result= res.data
					this.tikuList=result.data
				})
			},
      getList(){
      	this.$ajax.post("/tiku/page",{}).then(res=>{
      		var result= res.data
      		this.tikuList=result.data
      	})
      },
			xzst(){
				this.$router.push('/exam/index?tikuId='+this.tikuId)
			},
			getTiMuList(tikuId){
				this.$ajax.post("/tiku/timulist",{"tikuId":tikuId}).then(res=>{
					var result=res.data.data
					for (let i = 0; i < result.length; i++) {
						if(result[i].type==1){
							result[i].type="单选题"
						}else if(result[i].type==2){
							result[i].type='多选题'
						}else{
							result[i].type="判断题"
						}
					}
					this.tableData=result
				}
			)},
		},
		created() {
			this.getTikuList()
		}
	}
</script>

<style>
</style>
